package com.demo.controller;

import com.demo.assistent.Agent;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;
@Slf4j
@RestController
public class AgentController {

    @Resource
    private Agent agent;

    @GetMapping("/chat")
    public Flux<String> agent(String message, HttpSession session) {
//         从Session中获取登录用户ID
        String userId = session.getAttribute("userId").toString();
        log.info("名字-------------------------"+userId);
        if (userId == null) {
            return Flux.just("请先登录系统");
        }

        // 使用真实用户ID进行聊天
        return agent.chatMeg(Integer.parseInt(userId), message);
    }
}